package com.sqsf.javabean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
public class User{
    @Value("2")
    private int id;
    @Value("李四")
    private String name;
    @Value("20")
    private int age;
    //对于自定义类型注入 需要使用自动注入方式
    @Autowired//自动查找当前spring容器中匹配类型的对象并注入
    @Qualifier("role")//两个注解一同使用可以实现 当没有匹配类型时 使用指定id注入
    private Role r;

    public User() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Role getR() {
        return r;
    }

    public void setR(Role r) {
        this.r = r;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", r=" + r +
                '}';
    }

    //bean生命周期注解
    @PostConstruct//等价于bean标签中的init-method="init"
    public void init(){
        System.out.println("初始化方法....");
    }
    @PreDestroy//等价于bean标签中的destroy-method="destroy"
    public void destroy(){
        System.out.println("销毁方法.....");
    }

}
